package car_rental.entities.car;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import car_rental.entities.Comment;
import car_rental.entities.Dto;

@Entity
@Table(name = "car")
public class Car implements Dto {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id")
	private int id;
	
	@OneToOne(mappedBy = "car")
	@JoinColumn(name = "id")
	private Brand brand;
	
	@OneToOne(mappedBy = "car")
	@JoinColumn(name = "id")
	private Model model;
	
	@OneToOne(mappedBy = "car")
	@JoinColumn(name = "id")
	private CarClass carClass;
	
	@OneToOne(mappedBy = "car")
	@JoinColumn(name = "id")
	private Type type;
	
	@OneToMany(mappedBy = "car")
	@JoinColumn(name = "id")
	private List<Addon> addons;
	
	@Column(name = "year")
	private int year;
	
	@Column(name = "number")
	private String number;
	
	@OneToMany(mappedBy = "comment")
	private Set<Comment> carComments = new HashSet<Comment>();
	
	@OneToMany(mappedBy = "order")
	private Set<Comment> carOrders = new HashSet<Comment>();

	public Car() {}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Brand getBrand() {
		return brand;
	}

	public void setBrand(Brand brand) {
		this.brand = brand;
	}

	public Model getModel() {
		return model;
	}

	public void setModel(Model model) {
		this.model = model;
	}

	public CarClass getCarClass() {
		return carClass;
	}

	public void setCarClass(CarClass carClass) {
		this.carClass = carClass;
	}

	public Type getType() {
		return type;
	}

	public void setType(Type type) {
		this.type = type;
	}

	public List<Addon> getAddons() {
		return addons;
	}

	public void setAddons(List<Addon> addons) {
		this.addons = addons;
	}

	public int getYear() {
		return year;
	}

	public void setYear(int year) {
		this.year = year;
	}

	public String getNumber() {
		return number;
	}

	public void setNumber(String number) {
		this.number = number;
	}
	
	public Set<Comment> getCarComments() {
		return new HashSet<Comment>(carComments);
	}

	public void setCarComments(Set<Comment> carComments) {
		this.carComments = carComments;
	}
	

	public Set<Comment> getCarOrders() {
		return new HashSet<Comment>(carOrders);
	}

	public void setCarOrders(Set<Comment> carOrders) {
		this.carOrders = carOrders;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Car other = (Car) obj;
		if (id != other.id)
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Car [id=" + id + ", year=" + year + ", number=" + number + "]";
	}
	
}
